package com.ccb.lms.dao;

import java.sql.SQLException;
import java.util.List;

import com.ccb.lms.model.User;
import com.ibatis.sqlmap.client.SqlMapClient;

public class UserDAO implements IUserDAO {

	private SqlMapClient sqlMapClient = null;

	public boolean deleteUser(Integer id) throws SQLException {
		sqlMapClient.delete("user.deleteUser", id);
		return true;

	}

	public List<User> getAllUser() throws SQLException {
		List<User> list = null;
		list = sqlMapClient.queryForList("user.getAllUser");
		return list;
	}

	public User getUserById(Integer id) throws SQLException {
		User user = null;
		user = (User) sqlMapClient.queryForObject("user.getUserById", id);
		return user;

	}

	public boolean insertUser(User user) throws SQLException {
		sqlMapClient.insert("user.insertUser", user);
		return true;

	}

	public boolean isLogin(User user) throws SQLException {
		User u = (User) sqlMapClient.queryForObject("user.checkUser", user);
		if (u != null) {
			return true;
		}

		return false;
	}

	public boolean updateUser(User user) throws SQLException {
		sqlMapClient.update("user.updateUser", user);
		return true;

	}

	public SqlMapClient getSqlMapClient() throws SQLException {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

}
